const str1 = "abc ABC Abc aBc ";
//需求 都转换成abc 小写
const res = str1.replace("ABC", "abc"); //局限 只能指定转换ABC => abc
const res1 = str1.replace(/abc/gi, "abc"); // /abc/gi 标识符 gi:忽略大小写
console.log(res1); //abc ABC Abc aBc

//去掉所有数字
const str2 = "abc2369 ABC Abc aBc1598 ";
const res2 = str2.replace(/\d+/gi, ""); // /\d+/gi:全局匹配多个数字 => 标识符 gi:忽略大小写 \d+:匹配多个数字 +:[1,无穷],一个或者多个
console.log(res2); //abc ABC Abc aBc

//webpack loader.test原理匹配文件后缀
const str3 = " abc .vue";
const reg3 = /.vue$/i; //以.vue结尾
const res3 = reg3.test(str3);
console.log(res3); //true

const str4 = " abc.js";
const reg4 = /.e?js$/i; //.ejs或者.js
const res4 = reg4.test(str4);
console.log(res4); //true

// /^abc$/i=>就是一个abc
const str = "abc";
const reg = /^abc$/i; //以abc开头和结尾
console.log(reg.test(str)); //true

//a出现5次以上
const str5 = "aaacaaa";
const reg5 = /(a)[^\1]{5,}\1/g;
console.log(reg5.test(str5));

//exec方法
const str6 = "aabcd";
const reg6 = /bcd/;
console.log(reg.exec(str)); //[ 'abc', index: 0, input: 'abc', groups: undefined ]

//match方法
const str7 = "ab cab dabsahd";
const reg7 = /ab/gi; //不加g只搜索第一个 ,加g匹配全局
console.log(str7.match(reg7)); //[ 'ab', 'ab', 'ab' ]

console.log("---------------");
//matchALL方法
const str8 = "ab cab dabsahd";
const reg8 = /ab/gi; //不加g只搜索第一个 ,加g匹配全局
const res8 = str8.matchAll(reg7); //res8 => 迭代器
for (const i of res8) {
  console.log(i);
}
// [ 'ab', index: 0, input: 'ab cab dabsahd', groups: undefined ]
// [ 'ab', index: 4, input: 'ab cab dabsahd', groups: undefined ]
// [ 'ab', index: 8, input: 'ab cab dabsahd', groups: undefined ]

//split 不改变原数组
const str9 = "ab cab dabsahd";
const reg9 = /ab/;
console.log(str9.split(reg9));

//词边界 除\w都是词边界
const time = "now time 19:12! should eat sth but not 156:698;";
const timeReg = /\b\d\d:\d\d\b/gi; //19:12
console.log(time.match(timeReg));

// const str = "";
// const reg = ;
// console.log(reg.test(str));
